import Vue from 'vue'
import VueRouter from 'vue-router'
// 加载路由
Vue.use(VueRouter)


// 1、导入组件 （这样会一次性引入所有的路由）
/*
import Home from '../views/Home';
import About from "../views/About";
*/


//1.1 懒加载需要使用一个匿名函数来import, 表示使用的时候在import引入. 一个懒加载在打包的时候会单独打包成一个js文件.

/*const Home = function () {
  import('../views/Home')
}*/
const Home = () => import('../views/Home');
const About = () => import('../views/About');

const Fill = () => import('../views/fill/Fill');

const User = () => import('../views/user/User');
const Order = () => import('../views/order/Order');
const Good = () => import('../views/good/Good');
const Canvas = () => import('../views/canvas/Canvas.vue');

// 上传预览
const Preview = () => import('../views/preview/Preview.vue');

// 2、指定映射关系
const routes = [
  { // 配置一个默认跳转
    path: "/",
    redirect: "/fill"
  },
  {
    path: "/home",
    name: "Home",
    component: Home,
    children: [{
      path: 'user',
      component: User
    }, {
      path: 'order',
      component: Order
    }, {
      path: 'good',
      component: Good
    }
    ]
  }, {
    path: "/about",
    component: About
  },
  {
    path: "/preview",
    component: Preview
  },
  {
    path: "/canvas",
    component: Canvas
  },
  {
    path: "/fill",
    component: Fill
  }
]

// 3、暴露路由实例
export default new VueRouter({
  routes,
  /*mode: "history" // 默认是 hash 模式*/
})

